<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Sergey
 * Date: 09.08.13
 * Time: 13:06
 * To change this template use File | Settings | File Templates.
 */

namespace Hockey\Dao\Doctrine;

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

require_once BASE_PATH . "/vendor/autoload.php";

class DbConnection
{
    private $userName = 'root';
    private $password = '12345';
    private $host = 'localhost';
    private $port = '3306';
    private $dbName = 'hockey_simulator_db';

    private $entityManager;

    private static $_instance = null;

    private function __construct()
    {
        $isDevMode = true;
        $config = Setup::createAnnotationMetadataConfiguration(array(BASE_PATH . "/src/Hockey/Persistence"), $isDevMode);

        $conn = array(
            'user' => $this->userName,
            'password' => $this->password,
            'host' => $this->host,
            'port' => $this->port,
            'dbname' => $this->dbName,
            'driver' => 'pdo_mysql'
        );

        $this->entityManager = EntityManager::create($conn, $config);
    }

    public static function getInstance()
    {
        if (!self::$_instance)
            self::$_instance = new DbConnection();
        return self::$_instance;
    }

    /**
     * @return mixed
     */
    public function getEntityManager()
    {
        return $this->entityManager;
    }


}